{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Demo 01: Describing your geometry"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "In TIGRE the geometry is stored in a class. \n",
    "\n",
    "--------------------------------------------------------------------------\n",
    "--------------------------------------------------------------------------\n",
    "This file is part of the TIGRE Toolbox\n",
    "\n",
    "Copyright (c) 2015, University of Bath and\n",
    "                    CERN-European Organization for Nuclear Research\n",
    "                    All rights reserved.\n",
    "\n",
    "License:            Open Source under BSD.\n",
    "                    See the full license at\n",
    "                    https://github.com/CERN/TIGRE/license.txt\n",
    "\n",
    "Contact:            tigre.toolbox@gmail.com\n",
    "Codes:              https://github.com/CERN/TIGRE/\n",
    "--------------------------------------------------------------------------\n",
    "Coded by:          MATLAB (original code): Ander Biguri\n",
    "                   PYTHON : Reuben Lindroos,Sam Loescher\n",
    "\n",
    "To see a demo of what the geometry paramterers should look like, do as follows: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TIGRE parameters\n",
      "-----\n",
      "Distance from source to detector = 1536mm\n",
      "Distance from source to origin = 1000mm\n",
      "-----\n",
      "Detector parameters\n",
      "Number of pixels = [128 128]\n",
      "Size of each pixel = [ 3.2  3.2]mm\n",
      "Total size of the detector = [ 409.6  409.6]mm\n",
      "-----\n",
      "Image parameters\n",
      "Number of voxels = [64 64 64]\n",
      "Total size of the image = [256 256 256]mm\n",
      "Size of each voxel = [ 4.  4.  4.]mm\n",
      "-----\n",
      "Offset correction parameters\n",
      "Offset of image from origin = [0 0 0]mm\n",
      "Offset of detector = [0 0]mm\n",
      "-----\n",
      "Auxillary parameters\n",
      "Accuracy of forward projection = 0.5\n"
     ]
    }
   ],
   "source": [
    "import tigre\n"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "Geometry definition\n",
    "\n",
    "                  Detector plane, behind\n",
    "              |-----------------------------|\n",
    "              |                             |\n",
    "              |                             |\n",
    "              |                             |\n",
    "  Centered    |                             |\n",
    "    at O      A V    +--------+             |\n",
    "              |     /        /|             |\n",
    "     A Z      |    /        / |*D           |\n",
    "     |        |   +--------+  |             |\n",
    "     |        |   |        |  |             |\n",
    "     |        |   |     *O |  +             |\n",
    "     *--->y   |   |        | /              |\n",
    "    /         |   |        |/               |\n",
    "   V X        |   +--------+        U       |\n",
    "              .--------------------->-------|\n",
    "\n",
    "            *S"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We recommend using the template below and defining you're class as such: \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from __future__ import division\n",
    "import numpy as np\n",
    "\n",
    "\n",
    "class TIGREParameters:\n",
    "\n",
    "    def __init__(self, high_quality=True):\n",
    "        if high_quality:\n",
    "            # VARIABLE                                          DESCRIPTION                    UNITS\n",
    "            # -------------------------------------------------------------------------------------\n",
    "            self.DSD = 1536                                     # Distance Source Detector      (mm)\n",
    "            self.DSO = 1000                                     # Distance Source Origin        (mm)\n",
    "            # Detector parameters\n",
    "            self.nDetector = np.array((512, 512))               # number of pixels              (px)\n",
    "            self.dDetector = np.array((0.8, 0.8))               # size of each pixel            (mm)\n",
    "            self.sDetector = self.nDetector * self.dDetector    # total size of the detector    (mm)\n",
    "            # Image parameters\n",
    "            self.nVoxel = np.array((256, 256, 256))             # number of voxels              (vx)\n",
    "            self.sVoxel = np.array((256, 256, 256))             # total size of the image       (mm)\n",
    "            self.dVoxel = self.sVoxel/self.nVoxel               # size of each voxel            (mm)\n",
    "            # Offsets\n",
    "            self.offOrigin = np.array((0, 0, 0))                # Offset of image from origin   (mm)\n",
    "            self.offDetector = np.array((0, 0))                 # Offset of Detector            (mm)\n",
    "\n",
    "            # Auxiliary\n",
    "            self.accuracy = 0.5                                 # Accuracy of FWD proj          (vx/sample)\n",
    "            # Mode\n",
    "            self.mode = 'cone'                                  # parallel, cone                ...\n",
    "        else:\n",
    "            # VARIABLE                                          DESCRIPTION                    UNITS\n",
    "            # -------------------------------------------------------------------------------------\n",
    "            self.DSD = 1536                                     # Distance Source Detector      (mm)\n",
    "            self.DSO = 1000                                     # Distance Source Origin        (mm)\n",
    "            # Detector parameters\n",
    "            self.nDetector = np.array((128, 128))             # number of pixels              (px)\n",
    "            self.dDetector = np.array((0.8, 0.8))*4             # size of each pixel            (mm)\n",
    "            self.sDetector = self.nDetector * self.dDetector    # total size of the detector    (mm)\n",
    "            # Image parameters\n",
    "            self.nVoxel = np.array((64, 64 , 64))           # number of voxels              (vx)\n",
    "            self.sVoxel = np.array((256, 256, 256))             # total size of the image       (mm)\n",
    "            self.dVoxel = self.sVoxel / self.nVoxel             # size of each voxel            (mm)\n",
    "            # Offsets\n",
    "            self.offOrigin = np.array((0, 0, 0))                # Offset of image from origin   (mm)\n",
    "            self.offDetector = np.array((0, 0))                 # Offset of Detector            (mm)\n",
    "\n",
    "            # Auxiliary\n",
    "            self.accuracy = 0.5                                 # Accuracy of FWD proj          (vx/sample)\n",
    "            # Mode\n",
    "            self.mode=None                                      # parallel, cone                ...\n",
    "            self.filter=None"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
